using System.Collections.Generic;
using UnityEngine;

public class FloatingTextController : MonoBehaviour
{
    private static FloatingTextController floatingTextController;

    [SerializeField] FloatingTextCase[] floatingTextCases;
    private Dictionary<FloatingTextStyle, int> floatingTextLink;

    public void Inititalise()
    {
        floatingTextController = this;

        floatingTextLink = new Dictionary<FloatingTextStyle, int>();
        for (int i = 0; i < floatingTextCases.Length; i++)
        {
            floatingTextCases[i].Initialise();
            floatingTextLink.Add(floatingTextCases[i].FloatingTextStyle, i);
        }
    }

    public static FloatingTextBaseBehaviour SpawnFloatingText(FloatingTextStyle floatingTextStyle, string text, Vector3 position)
    {
        if(floatingTextController.floatingTextLink.ContainsKey(floatingTextStyle))
        {
            FloatingTextCase floatingTextCase = floatingTextController.floatingTextCases[floatingTextController.floatingTextLink[floatingTextStyle]];

            GameObject floatingTextObject = floatingTextCase.FloatingTextPool.GetPooledObject();
            floatingTextObject.transform.position = position;
            floatingTextObject.SetActive(true);

            FloatingTextBaseBehaviour floatingTextBehaviour = floatingTextObject.GetComponent<FloatingTextBaseBehaviour>();
            floatingTextBehaviour.Activate(text);

            return floatingTextBehaviour;
        }

        return null;
    }
}
